package com.corder.display.dao;

import java.util.List;

import com.jfinal.plugin.activerecord.Model;

/**
* �û��� 
 mysql> desc user;
+----------------+-------------+------+-----+-------------+----------------+
| Field          | Type        | Null | Key | Default     | Extra          |
+----------------+-------------+------+-----+-------------+----------------+
| id             | bigint(20)  | NO   | PRI | NULL        | auto_increment |
| userName       | varchar(20) | NO   |     | NULL        |                |
| password       | varchar(64) | NO   |     | NULL        |                |
| isAdmin        | int(11)     | NO   |     | 0           |                |
| chineseName    | varchar(20) | YES  |     | NULL        |                |
| lastLoginTime  | date        | YES  |     | NULL        |                |
| loginTimes     | int(11)     | YES  |     | 0           |                |
| loginToken     | varchar(64) | YES  |     |             |                |
| ip             | varchar(15) | YES  |     | '127.0.0.1' |                |
| lastModifyTime | bigint(20)  | YES  |     | NULL        |                |
+----------------+-------------+------+-----+-------------+----------------+
*/
public class User extends Model<User> {
	private static final long serialVersionUID = 1415310776039701929L;
	public static final User dao = new User();
	
	public List<User> checkUser(User user) {
		List<User> list = null;
		list = dao.find("select * from user where userName=? and password=?", new Object[]{user.getStr("userName"), user.getStr("password")});
		return list;
	}
	
	/**
	 * 根据登陆标志和登陆的ip去数据库查找对应的用户 
	 */
	public List<User> searchUserByTokenAndIp(String loginToken, String ip) {
		List<User> list = null;
		list = dao.find("select * from user where loginToken=? and ip=?", new Object[]{loginToken, ip});
		return list;
	}
	
	/**
	 * 重置最后一次操作时间 
	 */
	public void resetLoginStatus(User user) {
		user.set("lastModifyTime", System.currentTimeMillis()).update();
	}
	
}
